home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / dsp / dr.bub / 96000.lha / 96000 / appb / b125.asm < prev    next >
Assembly Source File  |  1992-04-28  |  4KB  |  57 lines

  1. ; This program was originally published in the Motorola DSP96002 Users Manual
  2. ; and is provided under a DISCLAIMER OF WARRANTY available from Motorola DSP
  3. ; Operation, 6501 William Cannon Drive West, Austin, Texas 78735-8598.  For
  4. ; more information, refer to the DSP96002 Users Manual, Appendix B, DSP
  5. ; Benchmarks.
  6. ;
  7. ; B.1.25    Argument Reduction  
  8. ;Argument reduction (AR) is the problem of having a desired floating  point number range and an ar-
  9. ;gument that is outside of the range.  The  argument is placed inside of the desired range by adding or 
  10. ;subtracting  multiples of the desired number range.  Of course, adding and  subtracting multiples of a 
  11. ;number is inherently slow and requires  infinite precision. Some simple methods can be used with 
  12. ;some  assumptions on the precision of the data and relative argument sizes.  
  13. ;The following program performs AR when the desired range is arbitrary  and the input value is arbi-
  14. ;trary. This may be used to reduce an angle to  the range of -pi to pi.  
  15. ;The following variables are defined: 
  16. ;           rmin = range minimum value, -pi in this example 
  17. ;           rmax = range maximum value, pi in this example 
  18. ;           range = rmax-rmin, 2*pi in this example 
  19. ;           o_range = 1.0/range 
  20. ;
  21. ;Assume the input is in d0.  
  22. ;rmin      equ  -3.14159 
  23. range     equ  2*3.14159 
  24. o_range   equ  1.0/range 
  25.  ;                                                          Program    ICycles 
  26.  ;                                                           Words 
  27.  
  28.  move             #range,d7.s   ;load desired range 
  29.  move             #rmin,d2.s    ;load range min 
  30.  move             #o_range,d3.s ;load reciprocal of range 
  31.  
  32.  fadd.s  d2,d0                  ;adjust to rmin               1     1 
  33.  fmpy.s  d0,d3,d0               ;scale the input              1     1 
  34.  floor   d0,d1                  ;get integer part             1     1 
  35.  fsub.s  d1,d0                  ;get fractional part          1     1 
  36.  fmpy.s  d7,d0d0                ;spread out fraction to range 1     1 
  37.  fadd.s  d2,d0                  ;adjust to rmin               1     1 
  38.   ;                                                           ---   --- 
  39.   ;                                                   Totals:  6     6 
  40.  
  41. ;The output is in d0. Note that the constant initialization is not  included in the benchmark because it 
  42. ;does not need to be executed every  time argument reduction is desired and is therefore application  
  43. ;dependent.  
  44. ;If the desired range begins at zero (i.e. the desired range is zero to  two pi), then the first and last 
  45. ;fadd instructions can be deleted for a  four cycle argument reduction.  
  46. ;This is one possible method for AR and it is efficient.  This method  will not work when the argument 
  47. ;divided by the result range has no  fractional part (in the current precision).  This is obvious since it  
  48. ;is the fractional part that contains the information relating to how  far the scaled argument is in the 
  49. ;reduced range. The integer part tells  how many times the range has wrapped around.  Typically, a 
  50. ;good  programmer will keep the argument to a few multiples of the desired  range. In most practical 
  51. ;applications, the argument may exceed the  desired range by several integral values.  In this case, the 
  52. ;presented  algorithms work very well.  After the final reduced argument has been  obtained, any incre-
  53. ;ments should be made from the reduced argument to  prevent eventual overflow and maintain maxi-
  54. ;mum precision.  
  55.